package com.zycfc.zsf.boot.web.util;

import com.zycfc.zsf.boot.mybatis.page.*;
import com.zycfc.zsf.boot.core.web.data.*;
import com.zycfc.zsf.boot.data.page.*;
import com.zycfc.zsf.boot.util.text.*;
import com.zycfc.zsf.boot.util.bean.*;
import java.util.*;
import org.slf4j.*;

public class DataResponseUtil
{
    private static final Logger log;
    
    public static DataResponse<?> succeed(final ZsfPage<?> zsfPage) {
        return (DataResponse<?>)DataResponse.succeed((Object)zsfPage.getList(), zsfPage.getPageNum(), zsfPage.getPageSize(), zsfPage.getTotal(), zsfPage.getPages());
    }
    
    public static DataResponse<?> succeed(final EsPage<?> esPage) {
        return (DataResponse<?>)DataResponse.succeed((Object)esPage.getList(), esPage.getPageNum(), esPage.getPageSize(), esPage.getTotal(), esPage.getPages());
    }
    
    public static DataResponse<?> succeed(final ZsfPage<?> zsfPage, final Class<?> clazz) {
        final List<?> list = (List<?>)zsfPage.getList();
        if (StringUtils.isEmpty((List)list)) {
            return (DataResponse<?>)DataResponse.succeed((Object)list, zsfPage.getPageNum(), zsfPage.getPageSize(), zsfPage.getTotal(), zsfPage.getPages());
        }
        final List<Object> destList = new ArrayList<Object>();
        for (final Object obj : list) {
            try {
                final Object destObj = BeanUtils.copyProperties((Class)clazz, obj);
                destList.add(destObj);
            }
            catch (Exception e) {
                DataResponseUtil.log.error("\u64cd\u4f5c\u5f02\u5e38", (Throwable)e);
            }
        }
        return (DataResponse<?>)DataResponse.succeed((Object)destList, zsfPage.getPageNum(), zsfPage.getPageSize(), zsfPage.getTotal(), zsfPage.getPages());
    }
    
    public static DataResponse<?> succeed(final EsPage<?> esPage, final Class<?> clazz) {
        final List<?> list = (List<?>)esPage.getList();
        if (StringUtils.isEmpty((List)list)) {
            return (DataResponse<?>)DataResponse.succeed((Object)list, esPage.getPageNum(), esPage.getPageSize(), esPage.getTotal(), esPage.getPages());
        }
        final List<Object> destList = new ArrayList<Object>();
        for (final Object obj : list) {
            try {
                final Object destObj = BeanUtils.copyProperties((Class)clazz, obj);
                destList.add(destObj);
            }
            catch (Exception e) {
                DataResponseUtil.log.error("\u64cd\u4f5c\u5f02\u5e38", (Throwable)e);
            }
        }
        return (DataResponse<?>)DataResponse.succeed((Object)destList, esPage.getPageNum(), esPage.getPageSize(), esPage.getTotal(), esPage.getPages());
    }
    
    public static boolean isSuccess(final DataResponse<?> dataResponse) {
        return dataResponse != null && "0000000".equals(dataResponse.getCode());
    }
    
    public static <T> DataResponse<T> copySucceed(final Object object, final Class<T> destClazz) {
        if (StringUtils.isEmpty(object)) {
            return (DataResponse<T>)DataResponse.succeed();
        }
        final T data = (T)BeanUtils.copyProperties((Class)destClazz, object);
        return (DataResponse<T>)DataResponse.succeed((Object)data);
    }
    
    static {
        log = LoggerFactory.getLogger((Class)DataResponseUtil.class);
    }
}
